package de.tum.in.eist.im.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;

import de.tum.in.eist.im.client.*;

/**
 * Displays the login window.
 * 
 * @author Christian Ivicevic (ga73yis@mytum.de)
 * @since 09-02-2011
 * @version 09-02-2011
 */
public class ChatView implements IView {
	/**
	 * The model to obtain data from.
	 */
	private ClientModel model;

	private Button logoutButton;

	/**
	 * Initialises the {@link IView} object with the specified
	 * {@link ClientModel} object to obtain data from.
	 * 
	 * @param model
	 *            the {@link ClientModel} to obtain data from.
	 * @return the initialised {@link IView} object which can be passed to the
	 *         {@link ClientView} to be rendered.
	 */
	@Override
	public IView create(ClientModel model) {
		this.model = model;
		return this;
	}

	/**
	 * Renders the current {@link IView} object.
	 */
	@Override
	public void render() {
		RootPanel.get().add(
				new Label("You are currently logged in as '"
						+ this.model.getCurrentUser().getUsername() + "'."));
		this.logoutButton = new Button("Logout");
		this.logoutButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				ClientController.get().logoutUser(
						ChatView.this.model.getCurrentUser());
			}
		});
		RootPanel.get().add(this.logoutButton);
	}

	/**
	 * Message sent when the {@link ClientModel} changes.
	 */
	@Override
	public void update() {
	}

}
